﻿using System.Collections.Generic;
using System.Windows.Automation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using QuickUIT.Controls;

namespace QuickUIT.Tests
{
    [TestClass]
    public class UIMenuItemTests
    {
        private BaseState _baseState;

        [TestInitialize]
        public void TestSetup()
        {
            _baseState = new BaseState(TestUtilities.GetTestApplicationFileName(), "@Name='QuickUIT Test Application'");
            _baseState.Execute();
        }

        [TestMethod]
        public void ShouldGetIsSelected()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIMenuItem menuItem = window.UIMenuItem("@Name='Menu 1'");
            Assert.IsFalse(menuItem.IsSelected);
        }

        [TestMethod]
        public void ShouldGetIsExpanded()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIMenuItem menuItem = window.UIMenuItem("@Name='Menu 1'");
            Assert.IsFalse(menuItem.IsExpanded);
        }

        [TestMethod]
        public void ShouldGetExpandCollapseState()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIMenuItem menuItem = window.UIMenuItem("@Name='Menu 1'");
            Assert.AreEqual(ExpandCollapseState.Collapsed, menuItem.ExpandCollapseState);
        }

        [TestMethod]
        public void ShouldExpand()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIMenuItem menuItem = window.UIMenuItem("@Name='Menu 1'");
            Assert.IsFalse(menuItem.IsExpanded);
            menuItem.Expand();
            Assert.IsTrue(menuItem.IsExpanded);
        }

        [TestMethod]
        public void ShouldCollapse()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UIMenuItem menuItem = window.UIMenuItem("@Name='Menu 1'");
            menuItem.Expand();
            menuItem.Collapse();
            Assert.IsFalse(menuItem.IsExpanded);
        }

        [TestMethod]
        public void ShouldGetAllMenuItems()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            List<UIMenuItem> menuItems = window.UIMenu("@AutomationId='menu1'").UIMenuItems();
            Assert.AreEqual(3, menuItems.Count);
            Assert.AreEqual("Menu 1", menuItems[0].Name);
            Assert.AreEqual("Menu 2", menuItems[1].Name);
            Assert.AreEqual("Menu 3", menuItems[2].Name);
        }

        [TestCleanup]
        public void TestTeardown()
        {
            _baseState.Cleanup();
        }
    }
}